package ${basepackage}.support.auth.finder;

import java.util.List;

import com.excalibur.shiro.finder.SecurityInfoFinder;
import com.excalibur.shiro.model.BaseAuthority;
import com.excalibur.shiro.model.BaseRole;
import com.excalibur.shiro.model.BaseUser;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ${basepackage}.mapper.op.AuthorityMapper;
import ${basepackage}.mapper.op.OpUserMapper;
import ${basepackage}.mapper.op.RoleMapper;

/**
 * @author "Jiance Qin"
 * 
 * @date 2014年2月28日
 * 
 * @time 下午6:24:27
 * 
 * @desc
 * 
 */
@Service(value="ExcaliburShiroInfoFinder")
public class DatabaseSecurityInfoFinder implements SecurityInfoFinder {

	@Autowired
	private OpUserMapper opUserMapper;

	@Autowired
	private RoleMapper roleMapper;

	@Autowired
	private AuthorityMapper authorityMapper;

	/**
	 * 
	 */
	public DatabaseSecurityInfoFinder() {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.general.op.security.interceptor.finder.BaseUserFinder#findUserByUsername
	 * (java.lang.String)
	 */
	@Override
	public BaseUser findUserByUsername(String username) {
		return opUserMapper.getByUsername(username);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.general.op.security.interceptor.finder.SecurityInfoFinder#
	 * findRolesByUserId(java.lang.Long)
	 */
	@Override
	public List<? extends BaseRole> findRolesByUserId(Long userId) {
		return roleMapper.getByUserId(userId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.general.op.security.interceptor.finder.SecurityInfoFinder#
	 * findAuthoritiesByRoleId(java.lang.Long)
	 */
	@Override
	public List<? extends BaseAuthority> findAuthoritiesByRoleId(Long roleId) {
		return authorityMapper.getByRoleId(roleId);
	}

}
